﻿using agsXMPP;
using ScriptsAPI;

namespace JClient {
    /* Procedury */
    public partial class ConnectionProvider {
        #region Bot

        #endregion
        #region User
        public void authorize(string cJid, string msg, int type) {
            switch (type) {
                case 0:
                    // Anulowanie
                    Client.PresenceManager.RefuseSubscriptionRequest(new Jid(cJid));
                    break;
                case 1:
                    // Autoryzuj
                    Client.PresenceManager.ApproveSubscriptionRequest(new Jid(cJid));
                    break;
                case 2:
                    // Prośba o anulowanie subskrybcji
                    Client.PresenceManager.Unsubscribe(new Jid(cJid));
                    break;
                case 3:
                    // Prośba o subskrypcję + dodanie kontaktu
                    if (msg != null)
						Client.PresenceManager.Subscribe(new Jid(cJid), msg);
                    else
                        Client.PresenceManager.Subscribe(new Jid(cJid));
                    break;
            }
        }
        public void addRosterItem(string RJid, string RNickname, string RGroup) {
            if (RJid != null && RJid != "") {
                if (RNickname == null || RNickname == "")
                    RNickname = null;
                if (RGroup == null || RGroup == "")
                    RGroup = "";
                Client.RosterManager.AddRosterItem(new Jid(RJid), RNickname, RGroup);
            }
        }
        public void editRosterItem(string RJid, string RNickname, string RGroup) {
            if (RJid != null && RJid != "") {
                if (RNickname == null || RNickname == "")
                    RNickname = null;
                if (RGroup == null || RGroup == "")
                    RGroup = "";
                Client.RosterManager.UpdateRosterItem(new Jid(RJid), RNickname, RGroup);
            }
        }
        public void delRosterItem(string RJid) {
            if (RJid != null)
                Client.RosterManager.RemoveRosterItem(new Jid(RJid));
        }
        #endregion
        #region Packets
        public void send(string user, string text, string subject, string thread, int type) {
            agsXMPP.protocol.client.Message mess;
            if (user != null && text != null) {
                mess = new agsXMPP.protocol.client.Message(new Jid(user), text);
                if (thread != null)
                    mess.Thread = thread;
                if (subject != null)
                    mess.Subject = subject;
                mess.Type = JFunctions.msgTypeToEnum(type);
                mess.Body = text;
                mess.To = new Jid(user);
                Client.Send(mess);
            }
        }
        #endregion
        #region Roster

        #endregion
    }
}